/** 程序入口 */

var fs = require("fs")
var config = require("./config/config.json")
var entityGenerator = require("./generator/entity-generator")
var oracleSqlGenerator = require("./generator/oracle-create-sql-generator")
var voGenerator = require("./generator/vo-generator")
var eolinkerGenerator = require("./generator/eolinker-generator")
var importUtil = require("./util/import-util")

// 从tab-txt文件读取数据，并组装为json
var json = importUtil.importTabTxt(process.argv[3])
// var json = JSON.parse(fs.readFileSync(process.argv[3]))
var generatorMap = {
    entity: entityGenerator,
    oracle: oracleSqlGenerator,
    vo: voGenerator,
    eolinker: eolinkerGenerator
}
// 生成代码
var code = generatorMap[process.argv[2]].generate(json)
// 将生成的代码输出到文件
fs.writeFile('../output/output-code.txt', code, 'utf8', function (error) {
    if (error) {
        console.log(error);
        return false;
    }
    if (config.print) {
        console.log(code)
    }
    console.log('代码已输出到output-code.txt');
})